using B.S.Medical.Api.Read.Application.Command.Patient;
using B.S.Medical.Api.Read.Application.Command.Register;
using B.S.Medical.Api.Read.DTOS;
using B.S.Medical.ErrorCode;
using MediatR;
using Microsoft.AspNetCore.Mvc;

namespace B.S.Medical.Api.Read.Controllers
{
    /// <summary>
    /// 患者控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class PatientController : ControllerBase
    {
        private readonly IMediator mediator;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="mediator">中介者</param>
        public PatientController(IMediator mediator)
        {
            this.mediator = mediator;
        }

        /// <summary>
        /// 获取患者列表
        /// </summary>
        /// <param name="request">请求参数</param>
        /// <returns>患者列表分页结果</returns>
        [HttpGet]
        public async Task<ApiPageing<PatientDTO>> GetPatients([FromQuery] GetPatientCommand request)
        {
            return await mediator.Send(request);
        }

        /// <summary>
        /// 根据ID获取患者信息
        /// </summary>
        /// <param name="patientId">患者ID</param>
        /// <returns>患者信息</returns>
        [HttpGet("{patientId}")]
        public async Task<ApiResult<PatientDTO>> GetPatientById(int patientId)
        {
            var command = new GetPatientByIdCommand { PatientId = patientId };
            return await mediator.Send(command);
        }
        
        /// <summary>
        /// 获取患者挂号队列信息
        /// </summary>
        /// <param name="patientId">患者ID</param>
        /// <returns>患者挂号队列信息</returns>
        [HttpGet("queue/{patientId}")]
        public async Task<ApiResult<List<PatientQueueInfoDto>>> GetPatientQueueInfo(long patientId)
        {
            var command = new GetPatientQueueCommand { PatientId = patientId };
            return await mediator.Send(command);
        }
    }
} 